/****** PLACE YOUR CUSTOM STYLES HERE ******/
var myChart1= echarts.init(document.getElementById('main1'), null, {width: 560, height: 350});
var myChart2 = echarts.init(document.getElementById('main2'));
var myChart3 = echarts.init(document.getElementById('main3'));
//var myChart4 = echarts.init(document.getElementById('main4'));
var myChart5 = echarts.init(document.getElementById('main6'));
// var myChart6 = echarts.init(document.getElementById('main6'));
var myChart7 = echarts.init(document.getElementById('main7'));

getNowFormatDate();

$(function init_myChart3() {
	$.ajax({
		url: "http://27.223.105.83:9000/prod-api/device/TempListForColdBigData",
		type: "GET",
		success: function(res) {
			// console.log(res);
			option = {
				legend: {
					icon: 'circle',
					itemWidth: 8,
					itemHeight: 8,
					itemGap: 10,
					top: '16',
					right: '10',
					data: ['制冷一(℃)','制冷二(℃)','制冷三(℃)'],
					textStyle: {
						fontSize: 14,
						color: '#a0a8b9'
					}
				},
				grid: {
					top:'46',
					left: '13%',
					right: '10',
					//bottom: '10%',
					containLabel: false
				},
				xAxis: [{
					type: 'category',
					axisLabel: {
						interval: 0,
						fontSize:14
					},
					axisLine: {
						show: false,
						lineStyle: {
							color: '#a0a8b9'
						}
					},
					axisTick: {
						show: false
					},
					data: res.data[0][1],
					offset: 10
				}],
				yAxis: [{
					type: 'value',
					name: '℃',
					nameGap: '2',
					min: 0,
					max: 30,
					axisLine: {
						show: false,
						lineStyle: {
							color: '#a0a8b9'
						}
					},
					axisLabel: {
						margin: 10,
						textStyle: {
							fontSize: 14
						}
					},
					splitLine: {
						lineStyle: {
							color: '#2b3646'
						}
					},
					axisTick: {
						show: false
					}
				}],
				"tooltip": {
					"trigger": "axis",
					transitionDuration: 0,
					backgroundColor: 'rgba(83,93,105,0.8)',
					borderColor: '#535b69',
					borderRadius: 8,
					borderWidth: 2,
					padding: [5, 10],
					formatter: function (params, ticket, callback) {
						var res = '';
						for (var i = 0, l = params.length; i < l; i++) {
							res += '' + params[i].seriesName + ' : ' + params[i].value + '<br>';
						}
						return res;
					},
					axisPointer: {
						type: 'line',
						lineStyle: {
							type: 'dashed',
							color: '#ffff00'
						}
					}
				},
				series: [{
					name: '制冷一(℃)',
					type: 'line',
					smooth: true,
					showSymbol: false,
					lineStyle: {
						color: '#AAFD2E',
						type: 'solid',
						width: 2
					},
					areaStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
								offset: 0,
								color: 'rgba(28,153,185, 0.3)'
							}, {
								offset: 0.8,
								color: 'rgba(28,153,185, 0)'
							}], false),
							shadowColor: 'rgba(0, 0, 0, 0.1)',
							shadowBlur: 10
						}
					},
					itemStyle: {
						normal: {
							color: '#AAFD2E'
						}
					},
					data: res.data[0][0]
				}, {
					name: '制冷二(℃)',
					type: 'line',
					smooth: true,
					showSymbol: false,
					lineStyle: {
						color: '#A18ECD',
						type: 'solid',
						width: 2
					},
					areaStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
								offset: 0,
								color: 'rgba(170,253,46, 0.3)'
							}, {
								offset: 0.8,
								color: 'rgba(170,253,46, 0)'
							}], false),
							shadowColor: 'rgba(0, 0, 0, 0.1)',
							shadowBlur: 10
						}
					},
					itemStyle: {
						normal: {
							color: '#A18ECD'
						}
					},
					data: res.data[1][0]
				},
				{
					name: '制冷三(℃)',
					type: 'line',
					smooth: true,
					showSymbol: false,
					lineStyle: {
						color:'#FD762E',
						type: 'solid',
						width: 2
					},
					areaStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
								offset: 0,
								color: 'rgba(253,118,46, 0.3)'
							}, {
								offset: 0.8,
								color: 'rgba(253,118,46, 0)'
							}], false),
							shadowColor: 'rgba(0, 0, 0, 0.1)',
							shadowBlur: 10
						}
					},
					itemStyle: {
						normal: {
							color: '#FD762E'
						}
					},
					data: res.data[2][0]
				}]
			};
			myChart3.setOption(option);
		}
	})
});
$(function init_myChart2() {
	$.ajax({
		url: 'http://27.223.105.83:9000/prod-api/device/TempListForOilBigData',
		type: 'GET',
		success: function(res) {
			// console.log(res);
			option = {
				legend: {
					icon: 'circle',
					itemWidth: 8,
					itemHeight: 8,
					itemGap: 10,
					top: '5',
					right: '10',
					data: ['一号蜡池(℃)','二号蜡池(℃)','三号蜡池(℃)','四号蜡池(℃)','五号蜡池(℃)'],
					textStyle: {
						fontSize: 14,
						color: '#a0a8b9'
					}
				},
				grid: {
					top:'46',
					left: '13%',
					right: '10',
					//bottom: '10%',
					containLabel: false
				},
				xAxis: [{
					type: 'category',
					axisLabel: {
						interval: 0,
						fontSize:14
					},
					axisLine: {
						show: false,
						lineStyle: {
							color: '#a0a8b9'
						}
					},
					axisTick: {
						show: false
					},
					data: res.data[0][1],
					offset: 10
				}],
				yAxis: [{
					type: 'value',
					name: '℃',
					nameGap: '2',
					min: 60,
					max: 100,
					axisLine: {
						show: false,
						lineStyle: {
							color: '#a0a8b9'
						}
					},
					axisLabel: {
						margin: 10,
						textStyle: {
							fontSize: 14
						}
					},
					splitLine: {
						lineStyle: {
							color: '#2b3646'
						}
					},
					axisTick: {
						show: false
					}
				}],
				"tooltip": {
					"trigger": "axis",
					transitionDuration: 0,
					backgroundColor: 'rgba(83,93,105,0.8)',
					borderColor: '#535b69',
					borderRadius: 8,
					borderWidth: 2,
					padding: [5, 10],
					formatter: function (params, ticket, callback) {
						var res = '';
						for (var i = 0, l = params.length; i < l; i++) {
							res += '' + params[i].seriesName + ' : ' + params[i].value + '<br>';
						}
						return res;
					},
					axisPointer: {
						type: 'line',
						lineStyle: {
							type: 'dashed',
							color: '#ffff00'
						}
					}
				},
				series: [{
					name: '一号蜡池(℃)',
					type: 'line',
					smooth: true,
					showSymbol: false,
					lineStyle: {
						normal: {
							width: 2
						}
					},
					areaStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
								offset: 0,
								color: 'rgba(137, 189, 27, 0.3)'
							}, {
								offset: 0.8,
								color: 'rgba(137, 189, 27, 0)'
							}], false),
							shadowColor: 'rgba(0, 0, 0, 0.1)',
							shadowBlur: 10
						}
					},
					itemStyle: {
						normal: {
							color: '#1cc840'
						}
					},
					data: res.data[0][0]
				}, {
					name: '二号蜡池(℃)',
					type: 'line',
					smooth: true,
					showSymbol: false,
					lineStyle: {
						normal: {
							width: 2
						}
					},
					areaStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
								offset: 0,
								color: 'rgba(219, 50, 51, 0.3)'
							}, {
								offset: 0.8,
								color: 'rgba(219, 50, 51, 0)'
							}], false),
							shadowColor: 'rgba(0, 0, 0, 0.1)',
							shadowBlur: 10
						}
					},
					itemStyle: {
						normal: {
							color: '#eb5690'
						}
					},
					data: res.data[1][0]
				},
				{
					name: '三号蜡池(℃)',
					type: 'line',
					smooth: true,
					showSymbol: false,
					lineStyle: {
						normal: {
							width: 2
						}
					},
					areaStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
								offset: 0,
								color: 'rgba(223,223,223, 0.3)'
							}, {
								offset: 0.8,
								color: 'rgba(223,223,223, 0)'
							}], false),
							shadowColor: 'rgba(0, 0, 0, 0.1)',
							shadowBlur: 10
						}
					},
					itemStyle: {
						normal: {
							color: '#DFDFDF'
						}
					},
					data: res.data[2][0]
				},
				{
					name: '四号蜡池(℃)',
					type: 'line',
					smooth: true,
					showSymbol: false,
					lineStyle: {
						normal: {
							width: 2
						}
					},
					areaStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
								offset: 0,
								color: 'rgba(229,244,19, 0.3)'
							}, {
								offset: 0.8,
								color: 'rgba(229,244,19, 0)'
							}], false),
							shadowColor: 'rgba(0, 0, 0, 0.1)',
							shadowBlur: 10
						}
					},
					itemStyle: {
						normal: {
							color: '#E5F413'
						}
					},
					data: res.data[3][0]
				},
				{
					name: '五号蜡池(℃)',
					type: 'line',
					smooth: true,
					showSymbol: false,
					lineStyle: {
						normal: {
							width: 2
						}
					},
					areaStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
								offset: 0,
								color: 'rgba(238,150,255, 0.3)'
							}, {
								offset: 0.8,
								color: 'rgba(238,150,255, 0)'
							}], false),
							shadowColor: 'rgba(0, 0, 0, 0.1)',
							shadowBlur: 10
						}
					},
					itemStyle: {
						normal: {
							color: '#EE96FF'
						}
					},
					data: res.data[4][0]
				}]
			};
			myChart2.setOption(option);
		}
	})
})
$(function init_myChart1(){
	$.ajax({
		url: "http://27.223.105.83:9000/prod-api/device/ConsumPieECharts",
		type:"GET",
		success: function(res) {
			// console.log(res)
			var datas = [];
			for (let i = 0; i < res.data.length; i++) {
				datas[i] = {value: res.data[i].value, name: res.data[i].name}
			}
			option = {
				tooltip : {
					trigger: 'item',
					formatter: "{a} <br/>{b} : {c} ({d}%)"
				},
				color:['#8fc31f','#f35833','#00ccff','#ffcc00','#f5e965','#a74faf','#ff9668','#fff'],
				 
				series : [
					{
						name: '资源总量构成',
						type: 'pie',
						radius : '40%',
						center: ['50%', '50%'],
						data: datas,
						itemStyle: {
							emphasis: {
								shadowBlur: 10,
								shadowOffsetX: 0,
								shadowColor: 'rgba(0, 0, 0, 0.5)'
							}
						},
						itemStyle: {
							normal: {
								label:{ 
									show: true, 
		//	                            position:'inside',
									formatter: '{b} : {c} ({d}%)' ,
									fontSize : 14,    //文字的字体大小
								}
							},
							labelLine :{show:true}
						}
					}
				]
			};
			// 使用刚指定的配置项和数据显示图表。
			myChart1.setOption(option);
		}
	})
})

$(function init_myChart5(){
	$.ajax({
		url: "http://27.223.105.83:9000/prod-api/device/consumAndProNLineS",
		type: 'get',
		success: function(res) {
			var XData=res.data[3];
			var yData=res.data[0];
			option = {
				backgroundColor:"",
				legend: {
					x: '60%',
					y: '0%',
					data: ['能耗(KWH)', '产能(个)', '蜡重(KG)'],
					textStyle: {
						color: '#9faeb5'
					}
				},
				xAxis: {
					axisTick: {
						show: false
					},
					splitLine: {
						show: false
					},
					splitArea: {
						show: false
					},
					data: XData,
					axisLabel: {
						formatter: function(value) {
							var ret = ""; //拼接加\n返回的类目项
							var maxLength = 1; //每项显示文字个数
							var valLength = value.length; //X轴类目项的文字个数
							var rowN = Math.ceil(valLength / maxLength); //类目项需要换行的行数
							if (rowN > 1) //如果类目项的文字大于3,
							{
								for (var i = 0; i < rowN; i++) {
									var temp = ""; //每次截取的字符串
									var start = i * maxLength; //开始截取的位置
									var end = start + maxLength; //结束截取的位置
									//这里也可以加一个是否是最后一行的判断，但是不加也没有影响，那就不加吧
									temp = value.substring(start, end);
									ret += temp; //凭借最终的字符串
								}
								return ret;
							} else {
								return value;
							}
						},
						interval: 0,
						fontSize: 14,
						fontWeight: 100,
						textStyle: {
							color: '#9faeb5',

						}
					},
					axisLine: {
						lineStyle: {
							color: '#4d4d4d'
						}
					}
				},
				yAxis: [{
					axisTick: {
						show: false
					},
					splitLine: {
						show: false
					},
					splitArea: {
						show: false
					},
					
					axisLabel: {
						textStyle: {
							color: '#9faeb5',
							fontSize: 16,
						}
					},
					axisLine: {
						lineStyle: {
							color: '#4d4d4d'
						}
					}
				},{
					type:'value',
					// name: '产能',
					min: 0,
					max: 100000,
					position: 'right',
					axisLabel: {
						textStyle: {
							color: '#9faeb5',
							fontSize: 16,
						}
					},
					axisLine: {
						show: true,
						lineStyle: {
							color: '#4d4d4d'
						}
					}
				}],
				"tooltip": {
					"trigger": "axis",
					transitionDuration: 0,
					backgroundColor: 'rgba(83,93,105,0.8)',
					borderColor: '#535b69',
					borderRadius: 8,
					borderWidth: 2,
					padding: [5, 10],
					formatter: function (params, ticket, callback) {
						var res = '';
						for (var i = 0, l = params.length; i < l; i++) {
							res += '' + params[i].seriesName + ' : ' + params[i].value + '<br>';
						}
						return res;
					},
					axisPointer: {
						type: 'line',
						lineStyle: {
							type: 'dashed',
							color: '#ffff00'
						}
					}
				},
				series: [{
					name:'产能(个)',
					type:"bar",
					yAxisIndex: 1,
					itemStyle: {
						normal: {
							color: {
								type: 'linear',
								x: 0,
								y: 0,
								x2: 0,
								y2: 1,
								colorStops: [{
									offset: 0,
									color: '#00d386' // 0% 处的颜色
								}, {
									offset: 1,
									color: '#0076fc' // 100% 处的颜色
								}],
								globalCoord: false // 缺省为 false
							},
							barBorderRadius: 15,
						}
					},
					label: {
							normal: {
								show: true,
								position: "top",
								textStyle: {
									color: "#ffc72b",
									fontSize: 10
								}
							}
						},
					data: res.data[1],
					barWidth: 16,
				},
				{
					name:'蜡重(KG)',
					type:"bar",
					yAxisIndex: 1,
					itemStyle: {
						normal: {
							color: {
								type: 'linear',
								x: 0,
								y: 0,
								x2: 0,
								y2: 1,
								colorStops: [{
									offset: 0,
									color: '#2652B4' // 0% 处的颜色
								}, {
									offset: 1,
									color: '#5C3590' // 100% 处的颜色
								}],
								globalCoord: false // 缺省为 false
							},
							barBorderRadius: 15,
						}
					},
					label: {
							normal: {
								show: true,
								position: "top",
								textStyle: {
									color: "#ffc72b",
									fontSize: 10
								}
							}
						},
					data: res.data[2],
					barWidth: 16,
				},{
					name:'能耗(KWH)',
					type:'line',
					itemStyle : {  /*设置折线颜色*/
						normal : {
							/* color:'#c4cddc'*/
						}
					},
					data:res.data[0]
				}]
			};
			myChart5.setOption(option);
		}
	})
	
})

$(function init_myChart7(){
	$.ajax({
		url: 'http://27.223.105.83:9000/prod-api/device/checkCountBigData',
		type: 'GET',
		success: function(res) {
			// console.log(res);
			option = {
				legend: {
					x: '60%',
					y: '0%',
					data: ['已完成','应完成(25项)'],
					textStyle: {
						color: '#9faeb5'
					}
				},
				xAxis: [{
					type: 'category',
					data: res.data[1],
					legend: {
						x: '60%',
						y: '0%',
						textStyle: {
							color: '#9faeb5'
						}
					},
					axisLine: {
						show: true,
						lineStyle: {
							color: '#4d4d4d',
							width: 0,
							type: 'solid'
						}
					},
					axisLabel:{
						show: true,
						textStyle: {
							color: '#9faeb5'
						}
					}
				}],
				yAxis: {
					type: 'value',
					name: '项',
					nameGap:'5',
					nameTextStyle: {
						color: '#a0a8b9'
					},
					min: 0,
					max: 35,
					axisLine: {
						show: true,
						lineStyle: {
							color: '#4d4d4d',
							width: 0,
							type: 'solid'
						}
					},
					axisLabel:{
						show: true,
						textStyle: {
							color: '#9faeb5'
						},
					}
				},
				"tooltip": {
					"trigger": "axis",
					transitionDuration: 0,
					backgroundColor: 'rgba(83,93,105,0.8)',
					borderColor: '#535b69',
					borderRadius: 8,
					borderWidth: 2,
					padding: [5, 10],
					formatter: function (params, ticket, callback) {
						var res = '';
						for (var i = 0, l = params.length; i < l; i++) {
							res += '' + params[i].seriesName + ' : ' + params[i].value + '<br>';
						}
						return res;
					},
					axisPointer: {
						type: 'line',
						lineStyle: {
							type: 'dashed',
							color: '#ffff00'
						}
					}
				},
				series: [
					{
						data: res.data[0],
						type: 'bar',
						name: '已完成',
						barWidth : 20,
						markLine: {
							lineStyle: {
								normal: {
									color: '#CEDAE7',
								}
							},
							data: [{
								yAxis: 25
							}]
						},
						itemStyle: {
							normal: {
								label: {
									show: true,
									position:"top",
									textStyle: {
										color: '#fff'
									}
								},
								color: {
									type: 'linear',
									x: 0,
									y: 0,
									x2: 0,
									y2: 1,
									colorStops: [{
										offset: 0,
										color: '#9B43C8' // 0% 处的颜色
									}, {
										offset: 1,
										color: '#422772' // 100% 处的颜色
									}],
									globalCoord: false // 缺省为 false
								},
								barBorderRadius: 15,
							}
						},
					}
				]
			};
			// 使用刚指定的配置项和数据显示图表。
				myChart7.setOption(option);
		}
	})
})
//获取当前时间
function getNowFormatDate() {
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    var Hour =  date.getHours();       // 获取当前小时数(0-23)
    var Minute =  date.getMinutes();     // 获取当前分钟数(0-59)
    var Second = date.getSeconds();     // 获取当前秒数(0-59)
    var show_day=new Array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');
    var day=date.getDay();
    if (Hour<10) {
        Hour = "0" + Hour;
    }
    if (Minute <10) {
        Minute = "0" + Minute;
    }
    if (Second <10) {
        Second = "0" + Second;
    }
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = '<div><p>'+year + '年' + month +'月' + strDate+'号</p><p>'+show_day[day]+'</p></div>';
    var HMS = Hour + ':' + Minute +':' + Second;
	var temp_time = year+'-'+month+'-'+strDate+' '+HMS;
    $('.nowTime li:nth-child(1)').html(HMS);
    $('.nowTime li:nth-child(2)').html(currentdate);
	//$('.topRec_List li div:nth-child(3)').html(temp_time);
    setTimeout(getNowFormatDate,1000);//每隔1秒重新调用一次该函数
}

// 正在生产的订单
$(function() {
	$.ajax({
		url: "http://27.223.105.83:9000/prod-api/device/getProductingOrder",
		type: "GET",
		success: function(res) {
			var orderList = res.data;
			console.log(orderList);
			for (let i = 0; i < orderList.length; i++) {
				$('.muban ul li').clone(true).appendTo('.maquee2 ul');
				$('.maquee2 ul').children().eq(i).children().eq(0).text(orderList[i].wdr);
				$('.maquee2 ul').children().eq(i).children().eq(1).text(orderList[i].partNo);
				$('.maquee2 ul').children().eq(i).children().eq(2).text(orderList[i].orderDescribe);
				$('.maquee2 ul').children().eq(i).children().eq(3).text(orderList[i].orderState);
				$('.maquee2 ul').children().eq(i).children().eq(4).text(orderList[i].progress);
				$('.maquee2 ul').children().eq(i).children().eq(5).text(orderList[i].yield);
			}
			// $('.muban ul li').remove();
		}
	})
})
// 当日订单信息
$(function() {
	$.ajax({
		url: "http://27.223.105.83:9000/prod-api/device/OtherOrder",
		type: "get",
		// dataType: "json",
		success: function(res) {
			// console.log(res);
			var orderList = res.data
			for (let i = 0; i < orderList.length; i++) {
				$('.muban ul li').clone(true).appendTo('.maquee ul');
				$('.maquee ul').children().eq(i).children().eq(0).text(orderList[i].wdr);
				$('.maquee ul').children().eq(i).children().eq(1).text(orderList[i].partNo);
				$('.maquee ul').children().eq(i).children().eq(2).text(orderList[i].orderDescribe);
				$('.maquee ul').children().eq(i).children().eq(3).text(orderList[i].orderState);
				if(orderList[i].progress == null) {
					$('.maquee ul').children().eq(i).children().eq(4).text('');
				}else {
					$('.maquee ul').children().eq(i).children().eq(4).text(orderList[i].progress);
				}
				if(orderList[i].yield == null) {
					$('.maquee ul').children().eq(i).children().eq(5).text('');
				}else {
					$('.maquee ul').children().eq(i).children().eq(5).text(orderList[i].yield);
				}
			}
			$('.muban ul li').remove();
		}
	})
})

$(function() {
	$.ajax({
		url: 'http://27.223.105.83:9000/prod-api/device/consumBigData',
		type:'GET',
		success: function(res) {
			console.log(res)
			$(".total .txt").eq(0).children().text(res.data[0].consumption);
			$(".total .txt").eq(1).children().text(res.data[1].consumption);
		}
	})
})


window.setTimeout(function(){				    	
	window.location.reload();				
},600000);